package passwd

import (
	"gitee.com/captials-team/ubdframe/src/common/utils"
	"strings"
)

// SaltMd5Password 加密controller
type SaltMd5Password struct {
	Salt string `json:"salt"`
}

func (ctr *SaltMd5Password) GenPassword(pass string, salts ...string) string {
	return GenSaltPasswordByMd5(pass, append(salts, ctr.Salt)...)
}

// SaltAesPassword 加密controller
type SaltAesPassword struct {
	Salt string `json:"salt"`
}

func (ctr *SaltAesPassword) GenPassword(pass string, salts ...string) string {

	return GenSaltPasswordByAes(pass, append(salts, ctr.Salt)...)
}

func GenSaltPasswordByMd5(pass string, salts ...string) string {
	salt := ""
	if len(salts) > 0 {
		salt = strings.Join(salts, "")
	}
	return utils.NewMd5Password(pass, salt)
}

func GenSaltPasswordByAes(pass string, salts ...string) string {
	salt := ""
	if len(salts) > 0 {
		salt = strings.Join(salts, "")
	}
	s, _ := utils.AesEncrypt([]byte(pass), []byte(salt))
	return s
}
